<!--20210304    zaq    创建vue文件-->
<!--20210511    zaq    默认分组-->
<!--20210531    zaq    完成删除模块测试-->

<template>
<!--查询说说-->
  <div class="select-text" style="text-align: left">
<!--    修改说说-->
    <el-dialog v-model="updateVisible" title="修改说说" style="width: 30%;"
               :before-close="closeUpdate"
    >
      <update-text-default v-bind:text="myText"></update-text-default>
    </el-dialog>

    <div style="width: 100%">
      <div style="text-align: right">
        <span style="color: #72767b">修改成功后需要关闭并点击查询&#12288;</span>
        <el-button @click="update(fList)">修改</el-button>
        <el-button @click="deleteBody(fList)">删除</el-button>
      </div>
      <div style="width: 80%">
        <span style="word-break:normal; width:auto; display:block; white-space:pre-wrap;word-wrap : break-word ;overflow: hidden ;font-size: 20px;">
        <p>
          {{fList.tText}}
        </p>
      </span>
      </div>
      <br><br>
      <div style="width: 100%;text-align: right">
        <span style="color: #3A4052">
          {{dateFormat(fList.tDate)}}&#12288;{{timeFormat(fList.tTime)}}
        </span>
      </div>
    </div>

    <el-divider>按时间倒序</el-divider>

    <div v-for="list in textLists">
      <div style="width: 100%;margin: 0;padding: 0">
        <div style="text-align: right">
          <span @click="update(list)">修改</span>&#12288;
          <span @click="deleteList(list)">删除</span>
        </div>
        <span style="font-size: 15px">
        {{list.tText}}
      </span><br><br>
        <div style="width: 100%;text-align: right">
        <span style="color: #3A4052">
          {{dateFormat(list.tDate)}}&#12288;{{timeFormat(list.tTime)}}
        </span>
        </div>

        <el-divider></el-divider>

      </div>

    </div>
    <el-form>
      <el-form-item>
        <el-input type="textarea"
                  :autosize="{ minRows: 2, maxRows: 4}"
                  style="width: 100%"
                  placeholder="有话要说"
                  v-model="tText"
                  class="input-with-select"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="reply">发送</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
import {getTextDefault_0000, insert_16211} from "../../api";
import {delete_16231} from "../../api";
import Update_text_default from "./Update_text_default";
import moment from "moment";

export default {
  name: "Select_text_default",
  props:{
    fList: {
      tId:'1',
      tDate:'20210511',
      tTime:'8:00',
      tText:'111',//内容
      tFId:'',//父对象ID
      tFGid:'',//父对象分组ID
      tFlag:'1',//评论数
      gId:'',//分组
      uId:'',//用户ID
      delete:'0',
      select:false
    }
  },
  data(){
    return{
      myText:'',
      updateVisible:false,
      tText:null,
      hidden:false,
      isHidden:function (flag) {
        console.log("flag="+flag)
        if (flag!='0')
          return false;
        else return true;
      },
      textLists:[
        {
          tId:'1',
          tDate:'20210511',
          tTime:'8:00',
          tText:'111',//内容
          tFId:'',//父对象ID
          tFGid:'',//父对象分组ID
          tFlag:'1',//评论数
          gId:'',//分组
          uId:'',//用户ID
          delete:'0',
        },
        {
          tId:'2',
          tDate:'20210511',
          tTime:'8:00',
          tText:'222',//内容
          tFId:'',//父对象ID
          tFGid:'',//父对象分组ID
          tFlag:'1',//评论数
          gId:'',//分组
          uId:'',//用户ID
          delete:'0',
        },
        {
          tId:'3',
          tDate:'20210511',
          tTime:'8:00',
          tText:'333',//内容
          tFId:'',//父对象ID
          tFGid:'',//父对象分组ID
          tFlag:'0',//评论数
          gId:'',//分组
          uId:'',//用户ID
          delete:'0',
        },
      ]
    }
  },
  methods:{
    deleteBody(body){
      const _this=this
      this.$confirm('此操作将永久删除该说说, 是否继续?', '删除说说', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delete_16231(body).then(resp=>{
          if(resp.code>0){
            _this.$message({
              type: 'success',
              message: '删除成功'
            });
            _this.$parent.$parent.$parent.$parent.getTextDefault()
            _this.$parent.$parent.$parent.$parent.selectListVisible=false
          }else{
            this.$message({
              type: 'error',
              message: '删除失败：'+resp.note
            });
          }
        }).catch(err=>{
          this.$message({
            type: 'error',
            message: '调用接口失败：'+err
          });
        })
      })
    },
    deleteList(body){
      const _this=this
      this.$confirm('此操作将永久删除该说说, 是否继续?', '删除说说', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delete_16231(body).then(resp=>{
          if(resp.code>0){
            _this.$message({
              type: 'success',
              message: '删除成功'
            });
            _this.getAll()
          }else{
            this.$message({
              type: 'error',
              message: '删除失败：'+resp.note
            });
          }
        }).catch(err=>{
          this.$message({
            type: 'error',
            message: '调用接口失败：'+err
          });
        })
      })
    },
    closeUpdate(done){
      this.updateVisible=false
      this.getAll()
      done()
    },
    update(body){
      this.myText=body.tText
      sessionStorage.setItem("up_gId",body.gId)
      sessionStorage.setItem("up_tId",body.tId)
      this.updateVisible=true
    },
    reply(){
      const _this=this
      //合法性检验
      if(_this.tText==null){
        _this.$message({
          type: 'error',
          message: '内容不能为空，请重新输入'
        });
      }else {
        var body = {
          uid: _this.fList.uId,
          tgId: _this.fList.tgId,
          gId: _this.fList.gId,
          tText: _this.tText,
          tFId: _this.fList.tId,//父对象ID
          tFGid: _this.fList.gId,//父对象分组ID
          tFlag: 0,//评论数
        }
        insert_16211(body).then(resp => {
          if (resp.code > 0) {
            _this.$message({
              type: 'success',
              message: '回复成功'
            });
            _this.tText=null
            _this.getAll()
          } else {
            _this.$message({
              type: 'error',
              message: '回复失败:' + resp.note
            });
          }
        }).catch(err => {
          _this.$message({
            type: 'error',
            message: '回复失败:' + err
          });
        })
      }
    },
    dateFormat:function(body) {
      var str=body.toString()
      var yyyy=str.substr(0,4)
      var mm=str.substr(4,2)
      var dd=str.substr(6,2)
      var create=''+yyyy+'-'+mm+'-'+dd
      return create;
    },
    timeFormat:function (body){
      var str=moment(body).format('HH : mm :ss')
      return str
    },
    getTextDefault(){
      const _this=this
      var uId=sessionStorage.getItem("uId")
      var body={
        uId:uId,
        gId:this.fList.gId,
        tFId:this.fList.tId,
        tFGid:this.fList.gId
      }
      getTextDefault_0000(body).then(resp=>{
        console.log(resp)
        _this.textLists=resp
      })
    },
    getAll() {
      const _this = this
      var uId = sessionStorage.getItem("uId")
      var gId = _this.fList.gId
      var body = {
        tId:_this.fList.tId,
        uId: uId,
        gId: gId,
        tFId: _this.fList.tId,
        tFGid: _this.fList.gId
      }
      getTextDefault_0000(body).then(resp => {
        console.log(resp)
        _this.textLists = resp
      }).catch(err => {
        console.log("err:" + err)
      })
    }
  },
  mounted() {
    this.fList.tId=sessionStorage.getItem("tId")
    this.fList.gId=sessionStorage.getItem("gId")
    console.log("id="+this.fList.tId)
    this.getAll()
  },
  components:{
    'update-text-default':Update_text_default,
  }
}
</script>

<style scoped>
.select-text{
  border: 0;
  margin: 0;
}
</style>